package com.github.common.extend.demo.config.transaction.distributed.message.adaptive;

import com.github.common.extend.demo.config.transaction.distributed.message.XMessageSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.ThreadLocalRandom;

/**
 * rocketmq消息发送器
 * @author X1993
 * @date 2022/9/23
 * @description
 */
@Slf4j
@Component
public class RocketXMessageSender implements XMessageSender<RocketMessageDTO> {

    @Override
    public void send(RocketMessageDTO message) throws Exception {
        //TODO 使用rocketmq组件发送消息
        if (ThreadLocalRandom.current().nextInt() % 5 == 0){
            throw new RuntimeException("消息发送失败");
        }
        log.info("消息推送成功");
    }

}
